package auth

import (
	"github.com/astaxie/beego/orm"
	"time"
)

type Auth struct {
	Id         int       `orm:"pk;auto"`
	AuthName   string    `orm:"description(权限名称);size(64)"`
	UrlFor     string    `orm:"description(url反转);size(255)"`
	Pid        int       `orm:"description(父节点id)"`
	Desc       string    `orm:"description(描述);size(255)"`
	CreateTime time.Time `orm:"type(datetime);auto_now;description(创建时间)"`
	IsActive   int       `orm:"column(is_active);description(1启用，0停用)"`
	IsDelete   int       `orm:"columns(is_delete);description(1删除，0未删除)"`
	Weight     int       `orm:"description(权重，数值越大，权重越大)"`
	Role       []*Role   `orm:"reverse(many)"` // role 反向关系
}

type Role struct {
	Id         int       `orm:"pk;auto"`
	RoleName   string    `orm:"size(64)"`
	Desc       string    `orm:"size(255)"`
	IsActive   int       `orm:"column(is_active)"`
	IsDelete   int       `orm:"column(is_delete)"`
	CreateTime time.Time `orm:"type(datetime);auto_now;description(创建时间)"`
	Auth       []*Auth   `orm:"rel(m2m)"` // auth 正向关系
	User       []*User   `orm:"rel(m2m)"` // auth 正向关系
}

type User struct {
	Id         int       `orm:"pk;auto"`
	UserName   string    `orm:"unique;column(user_name);size(64);description(用户名)"`
	Password   string    `orm:"size(32);description(密码)"`
	Age        int       `orm:"null;description(年龄)"`
	Gender     int       `orm:"null;description(1:男,2:女,3:未知)"`
	Phone      int64     `orm:"null;description(电话)"`
	Addr       string    `orm:"null;size(255);description(地址)"`
	IsActive   int       `orm:"null;description(1启用,0停用)；default(1)"`
	IsDelete   int       `orm:"null;description(1删除,0未删除)；default(0)"`
	CreateTime time.Time `orm:"auto_now;type(datetime);description(创建时间);null"`
	Role       []*Role   `orm:"reverse(many)"` // role 反向关系
}

func (u *User) TableName() string {
	return "sys_user"
}

func (r *Auth) TableName() string {
	return "sys_auth"
}

func (r *Role) TableName() string {
	return "sys_role"
}

func init() {
	orm.RegisterModel(
		new(Auth),
		new(Role),
		new(User),
	)
}
